var app = angular.module("myApp", []);

var iary = {
    data_cate: 'DEPT'
};
var inTrxObj = {
    trx_id: 'FBPBISDAT',
    action_flg: 'Q',
    iary: [iary]
};
var outTrxObj = comTrxSubSendPostJson(inTrxObj);

var nodesData = [];

if (outTrxObj.rtn_code == _NORMAL) {
    console.log(outTrxObj.oary);

    var nodes = {};

    var itemsCnt = outTrxObj.tbl_cnt;

    var items = outTrxObj.oary;

    for (var i = 0; i < itemsCnt; i++) {
        var data_id = items[i].data_id;
        var data_ext = items[i].data_ext;
        var ext_1 = items[i].ext_1;
        var ext_3 = items[i].ext_3;

        if (data_ext == "L1") {
            if (!nodes[data_id]) {
                nodes[data_id] = {};
                nodes[data_id].label = ext_1;
                nodes[data_id].children = [];
            } else {
                nodes[data_id].label = ext_1;
            }

        } else if (data_ext == "L2") {
            if (!nodes[ext_3]) {
                nodes[ext_3] = {};
                nodes[ext_3].children.push({
                    label: ext_1,
                    link: "#",
                    children: []
                });
            } else {
                nodes[ext_3].children.push({
                    label: ext_1,
                    link: "#",
                    children: []
                })
            }
        }
    }

    for (var property in nodes) {
        nodesData.push(nodes[property]);
    }

    console.log(nodesData);

}

/*创建 value对象 ：用于controller值传递*/
app.value("nodesJson", nodesData);


app.controller("myCtrl", function ($scope, nodesJson) {
    $scope.items = nodesJson;
     $scope.items=[
     {
     "label": "1000:制程",
     "children": [
     {
     "label": "1100:来料检验","link":"#",
     "children": []
     },
     {
     "label": "1200:入料管理","link":"#",
     "children": []
     },
     {
     "label": "1400:一般出账管理","link":"#",
     "children": []
     },
     {
     "label": "1700:保留","link":"#",
     "children": [{"label": "1701:test","link":"#"}]
     },
     {
     "label": "1800:释放","link":"#",
     "children": []
     }
     ]
     },
     {
     "label": "2000:特殊",
     "children": [
     {
     "label": "2100:交换箱","link":"#",
     "children": []
     },
     {
     "label": "2300:IPQC","link":"#",
     "children": []
     },
     {
     "label": "2500:跳站","link":"#",
     "children": []
     }
     ,
     {
     "label": "2600:在制仓管理","link":"#",
     "children": []
     }
     ,
     {
     "label": "2700:交换内部订单","link":"#",
     "children": []
     },
     {
     "label": "2800:生成天马客户资料","link":"#",
     "children": []
     }
     ]
     },
     {
     "label": "3000:设备",
     "children": [
     {
     "label": "3100:设备状态管理","link":"#",
     "children": []
     },
     {
     "label": "3200:点检执行界面","link":"#",
     "children": []
     },
     {
     "label": "3300:设备保养管理","link":"#",
     "children": []
     }
     ]
     },
     {
     "label": "4000:仓储",
     "children": [
     {
     "label": "4100:面板原料来料","link":"#",
     "children": []
     },
     {
     "label": "4200:面板原料发料","link":"#",
     "children": []
     },
     {
     "label": "4300:面板成品入库","link":"#",
     "children": []
     }
     ,
     {
     "label": "4400:面板成品出库","link":"#",
     "children": []
     }
     ,
     {
     "label": "4500:面板成品转库","link":"#",
     "children": []
     },
     {
     "label": "4A00:半成品入库","link":"#",
     "children": []
     },
     {
     "label": "4B00:半成品出库","link":"#",
     "children": []
     },
     {
     "label": "4C00:仓库返工","link":"#",
     "children": []
     }

     ]
     },
     {
     "label": "5000:排程",
     "children": [
     {
     "label": "5100:订单管理","link":"#",
     "children": []
     },
     {
     "label": "5200:工单管理","link":"#",
     "children": []
     },
     {
     "label": "5400:交货订单管理","link":"#",
     "children": []
     }

     ]
     },
     {
     "label": "6000:基础",
     "children": [
     {
     "label": "6100:工艺流程管理","link":"#",
     "children": []
     },
     {
     "label": "6200:版式管理","link":"#",
     "children": []
     },
     {
     "label": "6300:参数配置管理","link":"#",
     "children": []
     }
     ,
     {
     "label": "6400:产品维护","link":"#",
     "children": []
     }
     ,
     {
     "label": "6500:站点信息维护","link":"#",
     "children": []
     },
     {
     "label": "6700:物料管理","link":"#",
     "children": []
     },
     {
     "label": "6800:设备管理","link":"#",
     "children": []
     },
     {
     "label": "6900:Parameter管理","link":"#",
     "children": []
     },
     {
     "label": "6A00:数据收集管理","link":"#",
     "children": []
     },
     {
     "label": "6B00:箱子管理","link":"#",
     "children": []
     },
     {
     "label": "6C00:客户信息维护","link":"#",
     "children": []
     },
     {
     "label": "6D00:版式组管理","link":"#",
     "children": []
     }

     ]
     },
     {
     "label": "7000:品质",
     "children": [
     {
     "label": "7100:管制图设定","link":"#",
     "children": []
     },
     {
     "label": "7200:上报SPC数据","link":"#",
     "children": []
     },
     {
     "label": "7300:显示管制图","link":"#",
     "children": []
     }

     ]
     },
     {
     "label": "8000:报警",
     "children": [
     {
     "label": "8100",
     "children": [
     {
     "label":"8101:test","link":"#",
     "children":[]
     },
     {
     "label":"8102:test2","link":"#",
     "children":[]
     }
     ]
     }

     ]
     },
     {
     "label": "9000:查询",
     "children": [
     {
     "label": "9100:查询箱子信息","link":"#",
     "children": []
     },
     {
     "label": "9200:查询玻璃历史记录","link":"#",
     "children": []
     },
     {
     "label": "9300:查询玻璃信息","link":"#",
     "children": []
     }
     ,
     {
     "label": "9400:查询批次信息","link":"#",
     "children": []
     }
     ,
     {
     "label": "9500:查询内部订单信息","link":"#",
     "children": []
     },
     {
     "label": "9600:查询客户信息","link":"#",
     "children": []
     },
     {
     "label": "9700:查询产品型号信息","link":"#",
     "children": []
     },
     {
     "label": "9800:查询生产订单信息","link":"#",
     "children": []
     },
     {
     "label": "9A00:查询终检判定","link":"#",
     "children": []
     },
     {
     "label": "9B00:查询交货订单号信息","link":"#",
     "children": []
     },
     {
     "label": "9C00:查询站点信息","link":"#",
     "children": []
     }

     ]
     },
     {
     "label": "A000:权限",
     "children": [
     {
     "label": "A100:添加用户权限","link":"#",
     "children": []
     },
     {
     "label": "A200:用户与部门组织结构","link":"#",
     "children": []
     },
     {
     "label": "A300:权限特殊参数维护","link":"#",
     "children": []
     }
     ]
     },
     {
     "label": "C000:打印",
     "children": [
     {
     "label": "C200:补印来料批次标签","link":"#",
     "children": []
     },
     {
     "label": "C400:出货标签补印","link":"#",
     "children": []
     }
     ]
     }
     ];
});


